package net.vkits.common.dto;

import net.vkits.common.BaseModel;
import net.vkits.common.validations.UserDTOValidFirst;
import net.vkits.common.validations.UserDTOValidSecond;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.GroupSequence;

/**
 * Created by ethan-liu on 16/4/2.
 */
// 指定分组验证顺序, 先验证First分组，如果有错误立即返回而不会验证Second分组
// 接着如果First分组验证通过了，那么才去验证Second分组，最后指定UserDTO.class表示那些没有分组的在最后
@GroupSequence({UserDTOValidFirst.class, UserDTOValidSecond.class, UserDTO.class})
public class UserDTO extends BaseModel {

    @NotBlank(message = "{user.name.null}", groups = {UserDTOValidFirst.class})
    private String name;

    @NotEmpty(message = "{user.password.null}", groups = {UserDTOValidSecond.class})
    @Length(min = 6, max = 20, message = "{user.password.length.illegal}", groups = {UserDTOValidSecond.class})
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
